<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>embedme: src/StrUtil.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">embedme
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">StrUtil.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_str_util_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/******************************************************************************</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * This file is part of libemb.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * libemb is free software: you can redistribute it and/or modify</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * (at your option) any later version.</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * libemb is distributed in the hope that it will be useful,</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * GNU General Public License for more details.</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * along with libemb.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * Project: Embedme</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * Author : FergusZeng</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * Email  : cblock@126.com</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> * git    : https://gitee.com/newgolo/embedme.git</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * Copyright 2014~2020 @ ShenZhen ,China</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment">*******************************************************************************/</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#ifndef __STRING_UTIL_H__</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#define __STRING_UTIL_H__</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_base_type_8h.html">BaseType.h</a>&quot;</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="keyword">namespace </span>libemb{</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="keyword">using namespace </span>std;</div>
<div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="classlibemb_1_1_str_util.html">   39</a></span>&#160;<span class="keyword">class </span><a class="code" href="classlibemb_1_1_str_util.html">StrUtil</a>{</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<a class="code" href="_base_type_8h.html#a57e803e49526dc5ba8c1915c68708ae0">DECL_CLASSNAME</a>(<a class="code" href="classlibemb_1_1_str_util.html">StrUtil</a>)</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> toLower(<span class="keyword">const</span> std::string&amp; str);</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> toUpper(<span class="keyword">const</span> std::string&amp; str);</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> stringFormat(<span class="keyword">const</span> <span class="keywordtype">char</span> * fmt, ...);</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> replaceString(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; str,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; rep);</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> suffix(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; suffixFlag);</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> findString(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; start, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; end);</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> findString(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; pattern, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; before, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; after);</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> trimHeadWith(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; trimch);</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> trimTailBlank(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keywordtype">bool</span> trimHead=<span class="keyword">true</span>, <span class="keywordtype">bool</span> trimTail=<span class="keyword">true</span>);</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> trimAllBlank(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source);</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> trimHeadUnvisible(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source);</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="keyword">static</span> vector&lt;string&gt; splitString(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; splitFlag,<span class="keywordtype">bool</span> withFlag=<span class="keyword">false</span>);</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;    <span class="keyword">static</span> vector&lt;string&gt; cutString(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; startFlag,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; stopFlag,<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; cutFlag);</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> patternCount(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; source, <span class="keyword">const</span> <span class="keywordtype">string</span>&amp; pattern);</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> charToInt(<span class="keywordtype">char</span> ch);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">char</span> intToChar(<span class="keywordtype">int</span> val);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> hexBinarize(<span class="keyword">const</span> <span class="keywordtype">string</span> hexStr,<span class="keywordtype">char</span>* bytesBuf,<span class="keywordtype">int</span> len);</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> hexVisualize(<span class="keyword">const</span> <span class="keywordtype">char</span>* codebuf,<span class="keywordtype">int</span> len);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> hexStrToInt(<span class="keyword">const</span> std::string&amp; hexStr);</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> stringToInt(std::string intStr);</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">string</span> intToString(<span class="keywordtype">int</span> num);</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> isHexString(<span class="keyword">const</span> std::string&amp; hexString);</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> isIntString(<span class="keyword">const</span> std::string&amp; intString);</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">char</span>* memString(<span class="keywordtype">char</span>* mem, <span class="keywordtype">int</span> n, <span class="keywordtype">char</span>* str, <span class="keywordtype">int</span> size);</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;    <span class="keywordtype">char</span>* parseNextSection(<span class="keyword">const</span> <span class="keywordtype">char</span>* source,<a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a>* startPos,<span class="keyword">const</span> <span class="keywordtype">char</span>* endflag,<a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a>* section_len);</div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;    <span class="keywordtype">bool</span> parseNextString(<span class="keyword">const</span> <span class="keywordtype">char</span>* source,<a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a>* startPos, <span class="keyword">const</span> <span class="keywordtype">char</span>* endflag, <span class="keywordtype">char</span>* strbuf,<a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a> buflen);</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;    <span class="keywordtype">bool</span> parseNextInt(<span class="keyword">const</span> <span class="keywordtype">char</span>* source,<a class="code" href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">uint32</a>* startPos,<span class="keyword">const</span> <span class="keywordtype">char</span>* endflag,<a class="code" href="_base_type_8h.html#acb7826b9adaa8e650e7f090ec418cade">sint32</a>* result);</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;};</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;}</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;<span class="preprocessor">#endif</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="a_base_type_8h_html_a01991db9cc388cf9815386e13465f332"><div class="ttname"><a href="_base_type_8h.html#a01991db9cc388cf9815386e13465f332">libemb::uint32</a></div><div class="ttdeci">unsigned int uint32</div><div class="ttdef"><b>Definition:</b> BaseType.h:76</div></div>
<div class="ttc" id="a_base_type_8h_html_acb7826b9adaa8e650e7f090ec418cade"><div class="ttname"><a href="_base_type_8h.html#acb7826b9adaa8e650e7f090ec418cade">libemb::sint32</a></div><div class="ttdeci">signed int sint32</div><div class="ttdef"><b>Definition:</b> BaseType.h:72</div></div>
<div class="ttc" id="a_base_type_8h_html"><div class="ttname"><a href="_base_type_8h.html">BaseType.h</a></div><div class="ttdoc">基础类型头文件</div></div>
<div class="ttc" id="aclasslibemb_1_1_str_util_html"><div class="ttname"><a href="classlibemb_1_1_str_util.html">libemb::StrUtil</a></div><div class="ttdoc">字符串工具类</div><div class="ttdef"><b>Definition:</b> StrUtil.h:39</div></div>
<div class="ttc" id="a_base_type_8h_html_a57e803e49526dc5ba8c1915c68708ae0"><div class="ttname"><a href="_base_type_8h.html#a57e803e49526dc5ba8c1915c68708ae0">DECL_CLASSNAME</a></div><div class="ttdeci">#define DECL_CLASSNAME(ClassName)</div><div class="ttdef"><b>Definition:</b> BaseType.h:176</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
</html>
